/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.ipleiria.estg.es1.minesfinder;

import java.awt.BorderLayout;
import java.awt.LayoutManager;
import javax.swing.JPanel;

/**
 *
 * @author pedro.ferreira
 */
public class MinesFinder extends javax.swing.JFrame {

    /**
     * Creates new form MinesFinder
     */
    private TabelaRecords facil;
    private TabelaRecords medio;    
    private TabelaRecords dificil;
    
    public MinesFinder() {
        initComponents();
        facil = new TabelaRecords();
        medio = new TabelaRecords();
        dificil = new TabelaRecords();  
        
    facil.addTabelaRecordsListner(new TabelaRecordsListner(){         
        @Override         
        public void recordsAtualizados(TabelaRecords recordes) 
        {             
            recordesFacilActualizado(recordes);         
        }     
    });
            
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        lblNomeFacil = new javax.swing.JLabel();
        lblTempoFacil = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnFacil = new javax.swing.JButton();
        btnMedio = new javax.swing.JButton();
        btnDificil = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Principal");
        getContentPane().setLayout(new java.awt.BorderLayout());

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Mindes Finder v1.0");
        getContentPane().add(jLabel2, java.awt.BorderLayout.PAGE_START);

        lblNomeFacil.setText("jLabel1");

        lblTempoFacil.setText("jLabel3");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNomeFacil)
                    .addComponent(lblTempoFacil))
                .addGap(0, 66, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblNomeFacil)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblTempoFacil)
                .addContainerGap(158, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.LINE_START);

        jPanel2.setLayout(new java.awt.GridLayout(2, 2));

        btnFacil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pt/ipleiria/estg/es1/minesfinder/Jellyfish.jpg"))); // NOI18N
        btnFacil.setText("Fácil");
        btnFacil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFacilActionPerformed(evt);
            }
        });
        jPanel2.add(btnFacil);

        btnMedio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pt/ipleiria/estg/es1/minesfinder/Koala.jpg"))); // NOI18N
        btnMedio.setText("Médio");
        btnMedio.setToolTipText("");
        btnMedio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMedioActionPerformed(evt);
            }
        });
        jPanel2.add(btnMedio);

        btnDificil.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pt/ipleiria/estg/es1/minesfinder/Tulips.jpg"))); // NOI18N
        btnDificil.setText("Difícil");
        btnDificil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDificilActionPerformed(evt);
            }
        });
        jPanel2.add(btnDificil);

        btnSair.setText("SAIR");
        btnSair.setName(""); // NOI18N
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel2.add(btnSair);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btnSairActionPerformed

    private void btnFacilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFacilActionPerformed
        JanelaDeJogo janela=new JanelaDeJogo(new CampoMinado(9,9,10), facil);
        janela.setVisible(true);
    }//GEN-LAST:event_btnFacilActionPerformed

    private void btnMedioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMedioActionPerformed
        JanelaDeJogo janela=new JanelaDeJogo(new CampoMinado(16,16,40), medio);
        janela.setVisible(true);
    }//GEN-LAST:event_btnMedioActionPerformed

    private void btnDificilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDificilActionPerformed
        JanelaDeJogo janela=new JanelaDeJogo(new CampoMinado(16,40,90), dificil);
        janela.setVisible(true);
    }//GEN-LAST:event_btnDificilActionPerformed


    private void recordesFacilActualizado(TabelaRecords recordes) {
        lblNomeFacil.setText(recordes.getNome());     
        lblTempoFacil.setText(Long.toString(recordes.getRecord()/1000)); 
    }     
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MinesFinder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MinesFinder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MinesFinder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MinesFinder.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {                
                new MinesFinder().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDificil;
    private javax.swing.JButton btnFacil;
    private javax.swing.JButton btnMedio;
    private javax.swing.JButton btnSair;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblNomeFacil;
    private javax.swing.JLabel lblTempoFacil;
    // End of variables declaration//GEN-END:variables
}
